﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CreateRefundOrder.aspx.cs" Inherits="UI_Orders_CreateRefundOrder" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head runat="server">
    <title>退款信息</title>
    <script src="../../js/common.js" type="text/javascript"></script>
    <link href="../../css/admin.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery.easyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery.easyui/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery.easyui/jquery.min.js" type="text/javascript"></script>
    <script src="../../js/jquery.easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../js/jquery.easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script type="text/javascript">
       function checkqty(t, rowIndex) {
                var rows = $("#tbOrderDetail").datagrid('getRows');
                var row = rows[rowIndex];
                if (parseInt(t.value, 0) > parseInt(row.Quantity, 0)) {
                    alert('数量太大'); 
                    t.value = 0;
                }
                else {
                    row.Qty = t.value;
                }
            }

            $(function () {
                $("#tbOrderDetail").datagrid({
                    border: true,
                    height: 200,
                    width: 850,
                    title: '产品明细...',
                    remoteSort: false,
                    nowrap: true,
                    striped: false,
                    url: "../../TableHanders.aspx?act=q&tid=1025&type=0",
                    loadMsg: "正在加载,请稍后...",
                    columns: [[
				  { title: '', field: 'ck', checkbox: true },
      			  { title: '商品代号', field: 'ProductId', width: 80 },
      			  { title: '商品名称', field: 'ProductName', width: 280 },
      			  { title: '商品规格', field: 'ProductSpecification', width: 180 },
      			  { title: '退款数量', field: 'Qty', width: 80, formatter: function (val, rec, rowIndex) { return '<input value = "' + val + '" onchange = "checkqty(this,' + rowIndex + ');"></input>'; } },
      			  { title: '商品数量', field: 'Quantity', width: 80 }
      		  ]],
                    queryParams: {
                        "eBayUserId": $("#txteBayUserId").val(),
                        "OrderId": $("#txtOrderId").val()
                    },
                    onLoadSuccess: function (data) {
                        var rows = $("#tbOrderDetail").datagrid('getRows');
                        if (rows.length > 0) {
                            $("#txtRefundMoney").val(rows[0].RefundAmount);
                        }
                    }
                });
                $("#btnOK").click(function () {
                    $("#btnOK").attr('disabled', true);
                    var rows = $("#tbOrderDetail").datagrid('getSelections');
                    var data = {};
                    var pdata = [];
                    data.eBayUserId = $("#txteBayUserId").val();
                    data.OrderId = $("#txtOrderId").val();
                    data.Type = $("#ddlType").val();
                    data.Department = $("#ddlDepartment").val();
                    data.Status = $("#ddlStatus").val();
                    data.TotalPrice = $("#txtRefundMoney").val();

                    for (var i = 0; i < rows.length; i++) {
                        var quantity = rows[i].Qty;
                        if (quantity <= 0) { alert("数量必须大于0"); return; }
                        if (parseInt(quantity, 0) > parseInt(rows[i].Quantity, 0)) { alert("退款数量不能大于原数量"); return; }

                        pdata[pdata.length] = rows[i];
                    };

                    if (!confirm("确认执行此操作吗?")) { return; }

                    var url = "OrdersHandler.ashx?cmd=RefundMoney&ts=" + new Date().getTime();

                    $.getJSON(
                  url,
                  { 'pd': $.toJSON(pdata), 'data': $.toJSON(data) },
                  function (data) {
                      var retData = EvalData(data);
                      var code = retData.retCode;
                      if (code == 0) {
                          alert("操作完成");
                          window.returnValue = true;
                          window.close();
                      }                                                                                                                                                                                                     ///////////
                      else {
                          alert(retData.retMsg);
                      }
                      $("#btnOK").removeAttr('disabled');
                  });
                });
            });
    </script>
  </head>
  <body>
    <form id="form1" runat="server">
      <div>
        <table>
          <tr>
            <td>Ebay帐号:</td>
            <td><input id="txteBayUserId" readonly="readonly" style="width:200px" runat= "server"/></td>
            <td>订单号:</td>
            <td><input id="txtOrderId" readonly="readonly" style="width:200px" runat= "server"/></td>
            <td>退款金额:</td>
            <td><input  id = "txtRefundMoney" class = "easyui-numberbox" runat= "server" require = "true" precision = "2"  style = "width:200px"/></td>                
          </tr>
          <tr>
            <td>退款类型:</td>
            <td><select id = "ddlType" style = "width:206px" runat= "server" ></select></td>             
            <td>责任部门:</td>
            <td><select id = "ddlDepartment" style = "width:206px" runat= "server" name="D1" ></select></td>        
            <td>投诉状态:</td>
            <td><select id = "ddlStatus" runat = "server" style = "width:206px"></select></td>
          </tr>
        </table>
        <table id="tbOrderDetail"></table>
        <div style="text-align:right;height:30px;line-height:30px; padding:10px;">
		  <a id="btnOK" class="easyui-linkbutton" iconCls="icon-ok" href="javascript:void(0)" >OK</a>
		  <a id="btnCancel" class="easyui-linkbutton" iconCls="icon-cancel" href="javascript:void(0)" onclick="window.close();">Cancel</a>
		</div>
      </div>
    </form>
  </body>
</html>
